package com.zg.nacos.service.impl;



import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zg.common.core.dao.IDao;
import com.zg.common.core.service.BaseService;
import com.zg.nacos.dao.MicroUserDao;
import com.zg.nacos.domain.entity.MicroUser;
import com.zg.nacos.service.MicroUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>Description: </p>
 *
 * @author zhanfeng.liang
 * @since 2025/6/16 20:10
 */
@Slf4j
@Service
public class MicroUserServiceImpl extends BaseService<MicroUser, MicroUserDao> implements MicroUserService {

//    @Autowired
//    @Qualifier("microUserDao")
//    @Override
//    protected void setDao(IDao<MicroUser> dao) {
//        this.dao = dao;
//    }

    @Override
    protected LambdaQueryWrapper<MicroUser> buildQueryWrapper(MicroUser microUser) {
        LambdaQueryWrapper<MicroUser> qw = new LambdaQueryWrapper<>();
        if(microUser!=null){
            qw.eq(null!=microUser.getUsername(), MicroUser::getUsername, microUser.getUsername());
        }
        return qw;
    }

    @Override
    public MicroUser getByUsername(String username){
        MicroUser microUser = new MicroUser();
        microUser.setUsername(username);
        LambdaQueryWrapper<MicroUser> qw = buildQueryWrapper(microUser);
        MicroUser microUser1=baseDao.getOne(qw);
        return microUser1;
    }


    @Override
    public void removeByUsernames(List<String> usernames) {
        usernames.stream().forEach(t->{
            LambdaQueryWrapper<MicroUser> qw = new LambdaQueryWrapper<>();
            qw.eq(MicroUser::getUsername,t);
            baseDao.remove(qw);
        });
    }


}
